package main

import (
	"fmt"
	"time"
)

func test(x, y int) {
	var z int
	func() {
		defer func() {
			if err := recover(); err != nil {
				z = 0
			}
		}()
		z = x / y // x or y equal to zero, panic integer divide by zero
	}()
	fmt.Printf("x/y = %d \n", z)
}

func Try(fn func()) (catch string) {
	defer func() {
		if err := recover(); err != nil {
			catch = err.(string)
			time.Sleep(time.Second)
		}
	}()
	fn()
	return
}

func main() {
	catch := Try(func() {
		panic("test panic")
	})
	if catch != "" {
		fmt.Println(catch)
	}
}
